package org.ant.gui.panes;

import java.awt.GridBagLayout;

import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import org.ant.ctrl.CodesManager;
import org.ant.gui.layout.GBC;
import org.ant.util.Code;

public class StatPane extends JPanel {

	public static final String NAME = "Stat Table";

	private JTable table;
	private TableModel model;

	public StatPane() {
		super();
		model = new DefaultTableModel();
		table = new JTable(model);
		table.setRowHeight(50);
		setLayout(new GridBagLayout());
		add(table, new GBC(0, 0, 1, 1).setFill(GBC.HORIZONTAL).setWeight(1, 0)
				.setAnchor(GBC.NORTH));
		add(new JPanel(), new GBC(0, 1, 1, 1).setWeight(0, 1).setFill(GBC.BOTH));
	}

	public void update() {
		Code code = CodesManager.getInstane().getCurrentCode();
		if (code != null && !code.isNew()) {
			Object[] types = code.getTypes();
			Object[] dTypes = code.getDefineTypes();
			System.out.println(types.length);
			model = new DefaultTableModel(types.length + dTypes.length, 2);
			model.setValueAt("Types", 0, 0);
			for (int i = 0; i < types.length; i++) {
				model.setValueAt(types[i], i, 1);
			}
			model.setValueAt("Define Types", types.length, 0);
			for (int i = 0; i < dTypes.length; i++) {
				model.setValueAt(dTypes[i], types.length + i, 1);
			}
			table.setModel(model);

		}
	}
}
